/* 封装一个指令用以动态设置盒子高度 */
class iHeight{
    constructor($rootScope){
        this.$rootScope = $rootScope;
        this.restrict   = 'A';
    }

    link(scope, element, attrs, controller) {
        var winHeight = this.$rootScope.winHeight - 61;
        
        element.css({
            'min-height': winHeight + 'px'
        });

        window.onresize = () => {
            var navbar = angular.element(document.getElementById('navbar-static-side'));
            if ( window.screen.width < 768 || navbar.length == 0 ) return false;
            var sideH  = navbar[0].clientHeight;
            element.css({
                'min-height': window.innerHeight - 61 < sideH ? sideH : window.innerHeight - 61
            });
        }

        window.onscroll = () => {
            var navbar = angular.element(document.getElementById('navbar-static-side'));
            if ( window.screen.width < 768 || navbar.length == 0 ) return false;

            var sideH  = navbar[0].clientHeight,
                eleH   = element.height();

            sideH > eleH && element.css({'min-height': sideH})
        }
    }
}

iHeight.$inject = ['$rootScope'];

export default iHeight;